<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}
//change order status
if(isset($_REQUEST['orderstatus']) && ($_REQUEST['orderstatus'])!="") {
	   	$staus=$_REQUEST['orderstatus'];
}
if(isset($_REQUEST['a']) && trim($_REQUEST['a']) == "3")
{
	if(isset($_REQUEST['orderstatus']) && ($_REQUEST['orderstatus'])!="")
	   {
	   	$staus=$_REQUEST['orderstatus'];
	   }
	if(isset($_REQUEST['intid']) && ($_REQUEST['intid'])!="")
	{
		
		$intid=mysql_real_escape_string($_REQUEST['intid']);
		$del=mysql_query("delete from tblorders where intid='$intid'");
		$delstaushis=mysql_query("delete from `tblorderstatushistory` where `intorderid`='$intid'");
		$delorproduct=mysql_query("delete from `tblorderproductattributes` where `intorderid`='$intid'");
		$delorproductat=mysql_query("delete from `tblorderproducts` where `intorderid`='$intid'");
		header("location:orderqueue.php?orderstatus=$staus");
		die();
	}	
}

if(isset($_REQUEST['status']) && trim($_REQUEST['status']) != "")
{
	
	$stid = $_REQUEST['status'];	
	$stid=explode("@",$stid);
	$query = "UPDATE `tblorders` SET `intcurrentorderstatus`='".$stid[1]."' WHERE `intid`=".$stid[0];
	$sql=$obj_db->edit($query);	
	header("location:orderqueue.php?msg=chgtonext&orderstatus=".$staus);
	die();
}
?>
<?php include("inc/header.php");?>
<body>



<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr valign="top">
    <td align="center">
	<br />
	<table width="91%" border="0" cellpadding="2" cellspacing="2" class="border">
     <form action="" method="post" name="ser"> <tr>
        <td align="left" class="font">Search By Order No: </td>
        <td align="left">
            <?php
			if(isset($_REQUEST['search']) && ($_REQUEST['search'])!="")
			{
			$searh=$_REQUEST['search'];
			?>
			<input name="search" type="text"  value="<?php echo $searh;?>" size="15" />
			<?php
			}else{ ?>
			<input name="search" type="text" value="" size="15" />
			<?php }?>        </td>
        <td align="left">
            <input name="Submit" type="submit" class="btn" value="Go" />        </td>
        <td colspan="5" align="right">
		<!--<?php 
		if(isset($_REQUEST['orderstatus']) && ($_REQUEST['orderstatus'])==5)
		{
		?>
		<a href="supplierqueuehis.php?script=add" class="error">[NEW]</a>
		<?php }?>		--></td>
     </tr></form>
      <tr class="bg1">
        <td colspan="8"><strong>Customer Orders- Total...</strong></td>
        </tr>
      <tr align="center">
        <?php 
	   $rows="";
	 if(isset($_REQUEST['page']) && ($_REQUEST['page'])!="")
	 {
	 	$rows=$_REQUEST['page'];
	 
	  }	
	  ?><form name="form1" action="" method="post">
              <td colspan="9" align="left">
			  
			  Row per Page:
                <select name="page" onChange="document.form1.submit();">
                  <option value="0"<?php if($rows=='0'){echo "selected";}else{echo "";}?>>All</option>
                  <option value="5"<?php if($rows=='5'){echo "selected";}else{echo "";}?>>5 Per Page</option>
                  <option value="10"<?php if($rows=='10'){echo "selected";}else{echo "";}?>>10 Per Page</option>
                  <option value="15"<?php if($rows=='15'){echo "selected";}else{echo "";}?>>15 Per Page</option>
                </select>
				
			</td>
				</form>
        </tr>
      <tr align="center" class="tblbg3">
        <td align="center">Order No</td>
        <td align="center">Username(Email)</td>
        <td align="center">
		<?php 
		if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphaasc')
			{
		?>
		<a  class="ab1" href="ordertotal.php?sort=alphadesc">Total Purhased&nbsp;<img src="../images/down.gif" border="0" /></a>
		<?php 
			}
			else if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphadesc')
			{
		?><a class="ab1" href="ordertotal.php?sort=alphaasc">Total Purhased&nbsp;<img src="../images/up.gif" border="0" /></a>
		<?php }
			else
			{
			 ?>
			 <a class="ab1" href="ordertotal.php?sort=alphadesc">Total Purhased</a>
			 <?php
		 }?> </td>
		<td align="center">Order Queue Status</td>
		<td align="center">Invoice</td>
		<td align="center">Packing slip </td>
		<td align="center">View Order </td>
		<td align="center">Delete</td>
      </tr>
	   <?php
	   $staus="";
	   if(isset($_REQUEST['orderstatus']) && ($_REQUEST['orderstatus'])!="")
	   {
	   	$staus=$_REQUEST['orderstatus'];
	   }
		/**************************************
				PAGING CODE START
		**************************************/
			if(isset($_REQUEST['page']) && ($_REQUEST['page'])!=0) {
				$rows=$_REQUEST['page'];
				$rowperpage=$rows;
			} else {
				$rowperpage=$rows=10000;
			}
			$tablename="tblorders";
			$per_page_keywords= "intcustomerid != 0";
			$per_page_sorts= "";
			$wvar = "";
			include("system/paging.inc.php");

		/**************************************
				PAGING CODE ENDING
		**************************************/
	if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphaasc')
	{
	$sql_select = "select * 
	from  ".$tablename."
	where ".$per_page_keywords."
	order by `deccurrencyvalue` asc
	Limit ".($page_no*$row_per_page).",".$row_per_page;
	}
	else if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphadesc')
	{
	$sql_select = "select * 
	from  ".$tablename."
	where ".$per_page_keywords."
	order by `deccurrencyvalue` desc
	Limit ".($page_no*$row_per_page).",".$row_per_page;
	}
	else if(isset($_REQUEST['search']) && ($_REQUEST['search'])!="")
	{
	$searh=$_REQUEST['search'];
	$sql_select = "select * 
	from  ".$tablename."
	where intcustomerid != 0 and `intid` ='".$_REQUEST['search']."'
	Limit ".($page_no*$row_per_page).",".$row_per_page;
	}
	else if(isset($_REQUEST['orderstatus']) && ($_REQUEST['orderstatus'])!="")
	{
	$staus=$_REQUEST['orderstatus'];
	$sql_select = "select * 
	from  ".$tablename."
	where intcustomerid != 0 and intcurrentorderstatus='$staus'
	Limit ".($page_no*$row_per_page).",".$row_per_page;
	}
	else
	{
	
	$sql_select = "select * 
	from  ".$tablename."
	where intcustomerid != 0
	Limit ".($page_no*$row_per_page).",".$row_per_page;
	}
	$sql = $obj_db->select($sql_select);
	$nooforder=count($sql);
	if($sql)
	{
	$i=0;
	for($j=0;$j<count($sql);$j++)
	 { 
		$screen_id=$sql[$j]['intid'];
		 $i=$i+1;
		  ?>
       <form name="frm<?php echo $j;?>" method="post" action="">
       <tr align="center" class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';" onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
        <td><?php echo srchwordchangestyl($screen_id); ?></td>
        <?php 
		
		$sql_select1 = "SELECT * FROM `tblcustomers` WHERE `intcusid`=".$sql[$j]['intcustomerid'];
		$sql1 = $obj_db->select($sql_select1);
		if($sql1)
		{			
			for($j1=0;$j1<count($sql1);$j1++)
			{
			?>
		<td><a Title='Click here to E-Mail Customer' href="sendmail.php?customer=<?php echo $sql[$j]['intcustomerid'];?>" style="cursor:hand;" class="aa"><?php echo $sql1[$j1]['varcustemail'];?></a></td><?php }}?>
        <td>&pound;<?php echo $sql[$j]['totalvalue'];?></td>
		<td><a Title='Click here to Change order status' href="customerreport.php" class="aa">Change Order Status</a></td>
		<td><a href="#" Title='Click here for Invoice Details' onClick="window.open('invoice.php?order=<?php echo $screen_id;?>','','');" class="aa">Invoice</a></td>
		<td><a href="#" Title='Click here for Packing Slip Details' onClick="window.open('packingslip.php?order=<?php echo $screen_id;?>','','');" class="aa">Packing Slip</a></td>
		<td align="center"><a href="orderinfo.php?oid=<?php echo $sql[$j]['intid'];?>" class="aa">View &amp; Process Order</a></td>
		<td>
		<a Title="Click here to Delete" class="link" href="orderqueue.php?a=3&intid=<?php echo $screen_id;?>" onClick="return confirm('Are you sure to delete this record ?');"><img src="images/delete.bmp" alt="Delete" border="0"></a>
		</td>
      </tr>

	  <?php } } ?> </form>
      <tr>
        <td colspan="10">&nbsp;</td>
        </tr>
      <tr>
        <td colspan="10" align="center"><?php pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page); ?></td>
        </tr>
    </table>
	
	</td>
  </tr>
  <tr>
    <td align="center">&nbsp;</td>
  </tr>
</table>

</body>
</html>
